﻿using UnityEngine;
using static EColor;

public class CollideController : ActionController
{
    private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject platform = collision.gameObject;
        Platform_Collide p = platform.GetComponent<Platform_Energy>();
        if (CanCollide(p))
        {
            Vector2 point = collision.GetContact(0).point;
            Vector2 normalLine = CollideTool.NormalLineOfCollide(collision.collider.bounds, point);
            eventSystem.CollidePlatform?.Invoke(normalLine, platform,player);
        }
    }

    public bool CanCollide(Platform_Collide platform)
    {
        if (player.Velocity_LastFixedUpdate.magnitude < 15f || platform == null || !platform.Active)
            return false;
        return player.EColor == platform.targetColor || platform.targetColor == All;
    }
}
